-- @owner: opentestcase023
-- @date: 2022/02/24
-- @testpoint: 在向src表中插入数据之前，触发器动作向des表每行中插入数据

--step1:建表;expect:成功
drop table if exists t_trigger_src cascade;
drop table if exists t_trigger_des cascade;
create table t_trigger_src(id1 int, id2 int, id3 int) with (storage_type=ustore);
create table t_trigger_des(id1 int, id2 int, id3 int) with (storage_type=ustore);

--step2:在视图上创建触发器是指定before;expect:成功
create or replace function tri_insert_func() returns trigger as
$$
declare
begin
insert into t_trigger_des values(new.id1, new.id2, new.id3);
return new;
end
$$ language plpgsql;
/
drop trigger if exists insert_trigger on t_trigger_src cascade;
create trigger insert_trigger before insert on t_trigger_src
for each row 
execute procedure tri_insert_func();
/
select * from t_trigger_des;
insert into t_trigger_src values(1,1,1),(2,2,2);
select * from t_trigger_des;

--step3:清理环境;expect:成功
drop trigger if exists insert_trigger on t_trigger_src cascade;
drop table if exists t_trigger_src cascade;
drop table if exists t_trigger_des cascade;